﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using PermitsAndVisasLeadsSyncher.Model;
using PermitsAndVisasLeadsSyncher.Helpers;

namespace PermitsAndVisasLeadsSyncher.Data_Gateway
{
    internal class ProductGateway
    {
        public List<ProductInfo> FillListOfProductPresentInDatabase()
        {
            List<ProductInfo> Products = new List<ProductInfo>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSqlQuerytoReturnProductInfo());
            if (dt.Rows.Count <= 0)
            {
                return Products;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                Products.Add(new ProductInfo()
                {
                    ProductId = dataRow["Product_ID"].ToString(),
                    ProductName = dataRow["Product_Name"].ToString(),
                    ProductTypeName = dataRow["ProductType_Name"].ToString(),
                    ProductTypeResidentId = dataRow["ProductType_ResidenceID"].ToString(),
                    ProductDestinationId = dataRow["Product_DestinationID"].ToString()
                });
            }
            return Products;
        }
    }
}
